# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=libclc
# follow llvm versioning
pkgver=19.1.2
pkgrel=0
_llvmver=${pkgver%%.*}
pkgdesc="Open source implementation of the library requirements of the OpenCL C programming language"
url="https://libclc.llvm.org/"
arch="all"
license="Apache-2.0 WITH LLVM-exception"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	clang$_llvmver
	cmake
	llvm$_llvmver-dev
	llvm$_llvmver-static
	llvm$_llvmver-gtest
	samurai
	spirv-llvm-translator-dev
	"
checkdepends="llvm$_llvmver-test-utils"
subpackages="$pkgname-dev"
source="https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/libclc-$pkgver.src.tar.xz
	https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/cmake-$pkgver.src.tar.xz
	"
builddir="$srcdir/libclc-$pkgver.src"

build() {
	CC=clang-$_llvmver \
	CXX=clang++-$_llvmver \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLIBCLC_TARGETS_TO_BUILD="amdgcn--;amdgcn--amdhsa;amdgcn-mesa-mesa3d;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl;spirv-mesa3d-;spirv64-mesa3d-" \
		-DLLVM_CONFIG="llvm-config-$_llvmver" \
		-DLLVM_SPIRV=/usr/bin/llvm-spirv \
		-DCMAKE_MODULE_PATH="$srcdir/cmake-$pkgver.src/Modules"
	cmake --build build
}

check() {
	cmake --build build --target test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
ad9af068e1aa63eda7c6de1927aeef3494af287b66610a2185eac773c476e91e39ea575d1a9e666fd334663df93e48d71a262090503438e600cd3977f2c7ca61  libclc-19.1.2.src.tar.xz
9d13575a3e55a500dd5370591386a79ccc2164056448571620427f64236bf3fd1369090e3d5bdeef725b181d563462f331ff03c54e0667c01d079cf3af8b0c3f  cmake-19.1.2.src.tar.xz
"
